package com.study.demo_application_runner.config;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Set;

/**
 * @ClassName: MyApplicationRunner
 * @Description:
 * @author: WS
 * @date 2020/12/13
 * @Version: 1.0
 **/
@Component
public class MyApplicationRunner implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //获得所有的参数列表
        System.out.println(">>>>SourceArgs:"+ Arrays.toString(args.getSourceArgs()));
        //获取不带key的参数列表
        System.out.println(">>>>NonOptionArgs:"+args.getNonOptionArgs());
        //获取所有带key的参数
        Set<String> optionNames = args.getOptionNames();
        for (String optionName : optionNames) {
            System.out.println(optionName+":"+args.getOptionValues(optionName));
        }
    }
}
